/*
 * @FilePath: /tads/server/app/business/service/tactics_topo.go
 * @Author: wnina0x0
 * @Date: 2025-04-17 16:45:02
 * @Description:
 *
 * 版权信息 : 2025 by wnina0x0, All Rights Reserved.
 */
// /*
//  * @FilePath: /tads/server/app/business/service/scene_topo.go
//  * @Author: wnina0x0
//  * @Date: 2025-04-17 16:45:02
//  * @Description:
//  *
//  * 版权信息 : 2025 by wnina0x0, All Rights Reserved.
//  */
package service

import (
	"errors"
	"fmt"
	"tads/server/app/business/models"
	"tads/server/app/business/service/dto"
	"tads/server/core/sdk/service"

	"gorm.io/gorm"
)

type SceneTopo struct {
	service.Service
}

func (s *SceneTopo) Get(q *dto.TacticsTopoGetRequests, d *models.TacticsTopo) error {
	var err error
	if err = s.Postgres.Where(models.TacticsTopo{ID: q.ID}).First(d).Error; err != nil {
		if errors.Is(err, gorm.ErrRecordNotFound) {
			return fmt.Errorf("拓扑记录不存在")
		}
		return err
	}
	return nil
}

func (s *SceneTopo) Inset(q *dto.TacticsTopoInsetRequests) error {
	var err error
	var data models.TacticsTopo
	q.Generate(&data)
	if err = s.Postgres.Create(&data).Error; err != nil {
		return err
	}
	if err = s.Postgres.Where(models.Tactics{ID: q.TacticsId}).Updates(&models.Tactics{TacticsTopoId: data.ID}).Error; err != nil {
		return err
	}
	return nil
}

func (s *SceneTopo) Update(q *dto.TacticsTopoUpdateRequests) error {
	var err error
	var data models.TacticsTopo
	q.Generate(&data)
	if err = s.Postgres.Where(models.TacticsTopo{ID: q.ID}).Updates(data).Error; err != nil {
		return err
	}
	return err
}
